package com.itheima.log.controller;

import com.itheima.log.service.LogService;
import com.itheima.model.common.dtos.ResponseResult;
import com.itheima.model.common.dtos.TradeDto;
import com.itheima.model.common.enums.AppHttpCodeEnum;
import com.itheima.model.common.pojos.Trade;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/log")
@RestController
public class LogController {
    private static final Logger log = LoggerFactory.getLogger(LogController.class);
    @Autowired
    private LogService logService;

    /**
     * 查询日志
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody TradeDto tradeDto){
        return logService.list(tradeDto);
    }
    /**
     * 添加日志
     */
    @PostMapping("/record")
    public ResponseResult record(@RequestBody Trade trade){
        if (logService.save(trade)) {
            return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
        }else {
            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
        }
    }
}
